package main

import (
	"context"
	clientset "gitee.com/goeoeo/k8s-crd/pkg/generated/clientset/versioned"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/clientcmd"
	"log"
)

func main() {
	// 1. config
	// 2. client
	// 3. informer
	// 4. add event handler
	// 5. informer start

	config, err := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile)
	if err != nil {
		inClusterConfig, err := rest.InClusterConfig()
		if err != nil {
			checkErr(err)
		}
		config = inClusterConfig
	}

	clientSet, err := clientset.NewForConfig(config)
	checkErr(err)

	//list, err := clientSet.CrdV1().TestTypes("default").Get(context.Background(), "example-foo", v1.GetOptions{})
	//checkErr(err)
	//println(list.Name)
	list, err := clientSet.CrdV1().TestTypes("default").List(context.Background(), v1.ListOptions{})
	checkErr(err)
	for _, v := range list.Items {
		println(v.Name)
	}
}

func checkErr(err error) {
	if err != nil {
		log.Fatalf("config err:%s", err)
	}
	return
}
